package com.hollis公众号.list序列化;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Arrays;
import java.util.ConcurrentModificationException;

public class ArrayList implements Serializable {

	private static final long serialVersionUID = 2663380256938287187L;
	private transient Object[] elementData; // non-private to simplify nested class access
	private int currentIndex = 0;
	private int size = 0;

	public ArrayList() {
		super();
	}
	public ArrayList(int size) {
		super();
		this.elementData = new Object[size];
		this.size = size;
	}
	public Object[] getElementData() {
		return elementData;
	}
	public void setElementData(Object[] elementData) {
		this.elementData = elementData;
	}

	public void add(String s) {
		elementData[currentIndex++] = s;
	}
	@Override
	public String toString() {
		return "ArrayList [elementData=" + Arrays.toString(elementData) + "]";
	}

	private void readObject(ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
		// Read in size, and any hidden stuff
		s.defaultReadObject();
		// Read in capacity
		s.readInt(); // ignored
		elementData = new Object[size];
		if (size > 0) {
			Object[] a = elementData;
			// Read in all elements in the proper order.
			for (int i = 0; i < size; i++) {
				a[i] = s.readObject();
			}
		}
	}

	private void writeObject(ObjectOutputStream s) throws java.io.IOException {
		// Write out element count, and any hidden stuff
		s.defaultWriteObject();
		// Write out size as capacity for behavioural compatibility with clone()
		s.writeInt(size);
		// Write out all elements in the proper order.
		for (int i = 0; i < size; i++) {
			s.writeObject(elementData[i]);
		}
	}

}
